<?php namespace Common\Tag;
use Hdphp\View\TagBase;

class Common extends TagBase
{
	 /**
     * 标签声明
     * @var array
     */
    public $tags = array(
         //block说明 1：块标签  0：行标签
        'category' => array('block' => 1, 'level' => 4),

        //友情链接
        'link' => array('block' => 1, 'level' => 4),
    );
	
	public function _tag($attr, $content, &$hd){
		//要获取的条数
	  	$rows = isset($attr['rows']) ? (int)$attr['rows'] : 1000;
		$str = <<<str
<?php
	\$model = new \Common\Model\Tag;
	\$tagData = \$model->limit('$rows')->get();
	foreach(\$tagData as \$field):
	\$field['url'] = U('list/index',array('tid'=>\$field['tid']));
?>
{$content}
<?php 
	endforeach;
 ?>
str;
		return $str;
	}
	
	/**
     * 分类标签
     * @param $attr 属性
     * @param $content 内容
     * @param $hd HdView模型引擎对象
     */
    public function _category($attr, $content, &$hd)
    {
    		//分类的pid
    	$tid = isset($attr['tid']) ? (int)$attr['tid'] : NULL;
    	$pid = isset($attr['pid']) ? (int)$attr['pid'] : NULL;
		
		//where条件
		$where = '';
		//如果$attr['pid']不为空
		if(!is_null($pid)){
			$where = "->where('type_tid={$tid} and pid={$pid}')";
		}
    		$str = <<<stt
<?php
	//分类模型
	\$model = new \Common\Model\Category;
	\$cateData = \$model{$where}->get();
	foreach (\$cateData as \$field):
	//列表页地址
	\$field['url'] = U('list/index',array('cid'=>\$field['cid']));
?>
$content
<?php 
	endforeach;	
?>
stt;
		return $str;
    }
		
}






